package com.saikei.demoapp.db

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase

@Database(entities = [User::class,Book::class], version = 1, exportSchema = false)
abstract class DbDataBase : RoomDatabase() {
    abstract fun userDao(): UserDao
    abstract fun bookDao(): BookDao
    abstract fun userWithBookDao(): UserWithBookDao
    companion object {
        @Volatile
        private var INSTANCE: DbDataBase? = null
        fun getInstance(context: Context): DbDataBase {
            return synchronized(this) {
                INSTANCE?:Room.databaseBuilder(context, DbDataBase::class.java, "user.db")
                    .allowMainThreadQueries().build().also {
                        INSTANCE = it
                    }
            }
        }
    }
}